from __future__ import print_function, division
"""Encode object boxes and labels"""
import math
import numpy as np

from utils import *

class DataEncoder(object):
    """
    class for encode bbox
    """
    def __init__(self):
        super(DataEncoder, self).__init__()
        self._anchor_areas  = [32*32., 64*64., 128*128., 256*256., 512*512.] # p3->p7
        self._aspect_ratios = [1/2., 1/1., 2/1.]
        self._scale_ratios  = [1., pow(2, 1/3.), pow(2, 2/3.)]
    
    def _get_anchor_wh(self):
        """
        compute anchor width and height for each feature map
        returns:
            anchor_wh:  sized [#fm, #anchors_per_cell, 2]
        """
        _anchor_wh  = []
        for s in self._anchor_areas:
            for ar in self._aspect_ratios: # w/h = ar
                h   = math.sqrt(s/ar)
                w   = ar * h
                for sr in self._scale_ratios: # scale
                    _anchor_h   = h * sr
                    _anchor_w   = w * sr
                    _anchor_wh.append([_anchor_w, _anchor_h])

